using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace DownloadTool
{
    public partial class ConfirmDialog : Window
    {
        public bool Result { get; private set; } = false;

        public ConfirmDialog(string title, string message, string iconType = "Question")
        {
            InitializeComponent();
            
            TitleTextBlock.Text = title;
            MessageTextBlock.Text = message;
            
            // 设置图标
            string iconPath = "";
            switch (iconType.ToLower())
            {
                case "warning":
                    iconPath = "/Resources/warning.png";
                    Title = "警告";
                    break;
                case "error":
                    iconPath = "/Resources/error.png";
                    Title = "错误";
                    break;
                case "info":
                    iconPath = "/Resources/info.png";
                    Title = "信息";
                    break;
                case "question":
                default:
                    iconPath = "/Resources/question.png";
                    Title = "确认";
                    break;
            }
            
            try
            {
                // 尝试加载图标
                BitmapImage icon = new BitmapImage();
                icon.BeginInit();
                icon.UriSource = new Uri("pack://application:,,,/DownloadTool;component" + iconPath);
                icon.EndInit();
                IconImage.Source = icon;
            }
            catch
            {
                // 如果无法加载图标，使用默认图标
                IconImage.Visibility = Visibility.Collapsed;
            }
        }

        private void YesButton_Click(object sender, RoutedEventArgs e)
        {
            Result = true;
            DialogResult = true;
            Close();
        }

        private void NoButton_Click(object sender, RoutedEventArgs e)
        {
            Result = false;
            DialogResult = false;
            Close();
        }
        
        public static bool Show(Window owner, string title, string message, string iconType = "Question")
        {
            var dialog = new ConfirmDialog(title, message, iconType);
            dialog.Owner = owner;
            dialog.ShowDialog();
            return dialog.Result;
        }
    }
}